<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品类别</title>
<%@ include file="../../header_inc.jsp"%>
<script type="text/javascript" src="${ctx}/js/other.js"></script>

</head>
 
<body class="easyui-layout">
		
	<!-- <div data-options="region:'north',border:false"
		style="height: 0px; background: #EEEEEE; padding: 5px">
		
		<form id="formModule" method="post">
    	
    		名称：<input id="NAME"  maxlength="10" onchange="searchit();" class="easyui-validatebox textbox" type="text"  name="name" style="width:150px" ></input>         
    	</form>
		
		</div> -->
	<div data-options="region:'center',title:''">
		<table id="dg" class="easyui-datagrid" title="" fit="true"
			style="width: 700px; height: 250px"
			data-options="rownumbers:true,singleSelect:false,url:'/manage/commodityCategory/dataGrid',method:'get',toolbar:'#toolbar',fit:true,
				showFooter:false,pagination:true,idField:'categoryId'">
			<thead>
				<tr>
					<th data-options="field:'ck',checkbox:true">全选</th>
					<th data-options="field:'name',width:120,align:'center'">名称</th>
					<th data-options="field:'summary',width:300,align:'center'">说明</th>
					<th data-options="field:'status',width:70,align:'center',formatter:showStatus">状态</th>
					<!-- <th data-options="field:'_operate',width:180,align:'center',formatter:formatOper">操作</th> -->
				</tr>
			</thead>
		</table>
		<div id="toolbar" style="height: auto">
			${buttons }

			<script type="text/javascript">
				function append() {
					var params = {
		    	                winId:'addEditObjWin',
		    	                title:'添加类别',
		    	                width:300,
		    	                height:250,
		    	                showUrl:'${ctx}/manage/commodityCategory/add',
		    	                refresh_fun:function(){
		    	                	$('#dg').datagrid('uncheckAll');
		    	                    $('#dg').datagrid('reload');
		    	                }
		    	                
		    	        };
		    	        open_fun(params);
				}

				function edit() {
					 	var id=0;
		                var name=null;
		                var row = $('#dg').datagrid('getSelected');
		            	//var row = $('#dg').datagrid('getSelections');
		            	var len = $('#dg').datagrid('getSelections').length; 
		            	
		               	if(len>1){
		               		$.messager.alert("提示","只能选择一个进行更改!",'info');
		               	}
		               	else if(len==1 && row)
		                {
		                    id = row.categoryId;
		                    name = row.name;
		                        //winId,title,width,height,showUrl,okUrl,refresh_fun
		                        var params = {
		                                winId:'addEditObjWin',
		                                title:'修改 '+name+'',
		                                width:300,
		                                height:250,
		                                showUrl:'${ctx}/manage/commodityCategory/edit?id='+id,
		                                refresh_fun:function(){
		                                	$('#dg').datagrid('uncheckAll');
		                                    $('#dg').datagrid('reload');
		                                }
		                                
		                        };
		                        open_fun(params);   
		                    
		                }           
		                else
		                {
		                    $.messager.alert("提示","请选择要修改的信息!",'info');
		                }
				}

				function removeit() {
					var ids = [];
		        	var rows = $('#dg').datagrid('getSelections');
		        	var len = $('#dg').datagrid('getSelections').length; 
		        	for(var i=0; i<rows.length; i++){
		        		ids.push(rows[i].categoryId);
		        	}
		            if(!len)
		            {
		                $.messager.alert("提示","请选择要移除的数据！",'info');
		            }
		            else
		            {
		                $.messager.confirm("移除确认","是否要移除你选择的数据？",function(conf){
		                    if(conf)
		                    {
		                        var url = "${ctx}/manage/commodityCategory/remove?ids="+ids;
		                        $.getJSON(url, function(json){
		                            if(json.success==0)
		                            {
		                            	
		                            	$('#dg').datagrid('uncheckAll');
		                                $('#dg').datagrid('reload');
		                            }
		                            else
		                            {
		                                showErrMsg(json);
		                            }
		                        });
		                    }                                       
		                });
		            }
				}

				function deleteit() {
					var ids = [];
		        	var len = $('#dg').datagrid('getSelections').length; 
		        	var rows = $('#dg').datagrid('getSelections');
		        	for(var i=0; i<rows.length; i++){
		        		ids.push(rows[i].categoryId);
		        	}
		            if(!len)
		            {
		                $.messager.alert("提示","请选择要删除的数据！",'info');
		            }
		            else
		            {	
		                $.messager.confirm("删除确认","是否要删除你选择的数据？",function(conf){
		                    if(conf)
		                    {	
		                        var url = "${ctx}/manage/commodityCategory/delete?ids="+ids;
		                        $.getJSON(url, function(json){
		                            if(json.success==0)
		                            {
		                            	$('#dg').datagrid('uncheckAll');
		                                $('#dg').datagrid('reload');
		                            }
		                            else
		                            {
		                            	$.messager.alert("提示",json.msg,'info');
		                            }
		                        });
		                    }                                       
		                });
		            }
				}

				function searchit() {
					$("#dg").datagrid("load", sy.serializeObject($('#formModule').form()));
				}
				
				//右侧菜单
				function formatOper(val, row, index) {
					return '<a href="#" onclick="editone();"><input class="btn" type="button" value="修改" ></a>  <a href="#" onclick="deleteone();"><input class="btn" type="button" value="删除" ></a>  <a href="#" onclick="removeone();"><input class="btn" type="button" value="移除" ></a>';
				}
				
				
				
				 //以下三个函数为单个操作
		        function editone(){
		        	//alert(row);
		        	var row = $('#dg').datagrid('getSelected');
		        	var id = row.categoryId;
		        	var name = row.name;
		            //winId,title,width,height,showUrl,okUrl,refresh_fun
		            var params = {
		                    winId:'addEditObjWin',
		                    title:'修改 '+name+' 的信息',
		                    width:300,
		                    height:250,
		                    showUrl:'${ctx}/manage/commodityCategory/edit?id='+id,
		                    refresh_fun:function(){
		                    	$('#dg').datagrid('uncheckAll');
		                        $('#dg').datagrid('reload');
		                    }
		                    
		            };
		            open_fun(params);   
		        	
		        }
		        
		        
		        function removeone(){
		        	var row = $('#dg').datagrid('getSelected');
		        	var id = row.categoryId;
		        	var name = row.name;
		        	 $.messager.confirm("移除确认",'移除&nbsp; <span style="color:red;font-weight:bold">'+id+'-'+name+'</span> &nbsp;？',function(conf){
		                 if(conf)
		                 {
		                     var url = "${ctx}/manage/commodityCategory/remove?ids="+id;
		                     $.getJSON(url, function(json){
		                         if(json.success==0)
		                         {
		                         	
		                         	$('#dg').datagrid('uncheckAll');
		                             $('#dg').datagrid('reload');
		                         }
		                         else
		                         {
		                             showErrMsg(json);
		                         }
		                     });
		                 }                                       
		             });
		        	
		        }
		        
		        
		        function deleteone(){
		        	var row = $('#dg').datagrid('getSelected');
		        	var id = row.categoryId;
		        	var name = row.name;
		        	 $.messager.confirm("删除确认",'删除&nbsp; <span style="color:red;font-weight:bold">'+id+'-'+name+'</span> &nbsp;？',function(conf){
		                 if(conf)
		                 {	
		                     var url = "${ctx}/manage/commodityCategory/delete?ids="+id;
		                     $.getJSON(url, function(json){
		                         if(json.success==0)
		                         {
		                         	$('#dg').datagrid('uncheckAll');
		                             $('#dg').datagrid('reload');
		                         }
		                         else
		                         {
		                        	 showErrMsg(json);
		                         }
		                        
		                     });
		                 }                                       
		             });
		    	
		        }
		        
			</script>

		</div>

	</div>
	<div id="addEditObjWin" ></div>		<!-- 打开和编辑dialog -->
</body>
</html>